<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$offset = 0;
$limit = 10;
$games = dt_list_top_games($offset, $limit);
$users = dt_list_top_users($offset, $limit);

$resultg = array();
foreach($games as $g) {
    if (count($resultg) >= $limit) {
        break;
    }
    $game = dt_get_game($g->game_id);
    if($game) {
        $game->ratings = $g->ratings;
        $noun_user = dt_get_user_by_user_id($games[$i]->noun_id);
        $adjective_user = dt_get_user_by_user_id($games[$i]->adjective_id);
        //var_dump($noun_user);
        //var_dump($adjective_user);
        if($noun_user) {
            $game->noun_fbid = $noun_user->facebook_id;
            $game->noun_name = $noun_user->fullname;
        }
        if($adjective_user) {
            $game->adjective_fbid = $adjective_user->facebook_id;
            $game->adjective_name = $adjective_user->fullname;
        }
        $resultg[] = $game;
    }
}

$resultu = array();
foreach($users as $uid => $urep) {
    if (count($resultu) >= $limit) {
        break;
    }
    $user = dt_get_user_by_user_id($uid);
    if($user) {
        $user->reputation = $urep;
        $resultu[] = $user;
    }
}

$result = array(
    'games' => $resultg,
    'users' => $resultu
);
       
echo json_encode(export_result(200, $result));

?>
